package com.shao.im.webSocket.base;

import com.shao.im.entity.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 自定义入栈消息处理器
 */
@Slf4j
public abstract class BaseChannelInHandler extends SimpleChannelInboundHandler<Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        log.debug("[webSocket] webSocket连接 - {}", ctx);
        if (msg.getAction() == action()) {
            handler(ctx, msg);
        } else {
            ctx.fireChannelRead(msg);
        }
    }

    protected abstract int action();

    protected abstract void handler(ChannelHandlerContext ctx, Message message);
}
